using System;
using System.Xml;

using Google.Apps.Provisioning.Utilities;

namespace Google.Apps.Provisioning.Actions
{
    /// <summary>
    /// Implements steps specific to an UpdateUser API call.
    /// </summary>
    internal class UpdateUserAction : BaseProvisioningAction
    {
        private GoogleUser user;

        public UpdateUserAction( GoogleUser user ) : base(
            "Google.Apps.Provisioning.XmlTemplates.UpdateUser.xml",
            "https://www.google.com/a/services/v1.0/Update/Account" )
        {
            this.user = user;
        }

        public override void ProcessRequestXml( XmlDocument doc, XmlNamespaceManager ns )
        {
            doc.SelectSingleNode( "hs:rest/hs:queryData", ns ).InnerText = user.UserName;
            
            XmlNode updateNode = doc.SelectSingleNode( "hs:rest/hs:UpdateSection", ns );

            updateNode.SelectSingleNode( "hs:firstName", ns ).InnerText = user.FirstName;
            updateNode.SelectSingleNode( "hs:lastName", ns ).InnerText = user.LastName;
            updateNode.SelectSingleNode( "hs:password", ns ).InnerText = user.Password;
        }
    }
}
